using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using NCI.EasyObjects;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;
using CMS.BLL.Entity;
using CMS.DAL;

namespace CMS.BLL
{
   public class FAQs
    {
          #region Common
        public eFAQs Data;

        public FAQs()
        {
            Data = new eFAQs();
		}

        ~FAQs()
        {
		}

		public virtual void Dispose()
        {
		}

        public int DeleteById(int ID)
        {
            int nResult = 0;
            cFAQs objDAL = new cFAQs();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.MarkAsDeleted();
                objDAL.Save();
                nResult = ID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        public void LoadById(int ID)
        {
            cFAQs objDAL = new cFAQs();
            objDAL.LoadByPrimaryKey(ID);
            ConvertData(objDAL);
        }

        public int Insert()
        {
            int nResult = 0;
            cFAQs objInfor = new cFAQs(); 
            try
            {
                objInfor.AddNew();
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = objInfor.FAQID;
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }

        public int Update(int ID)
        {
            int nResult = 0;
            cFAQs objInfor = new cFAQs();
            try
            {
                objInfor.LoadByPrimaryKey(ID);
                this.MappingData(objInfor);
                objInfor.Save();
                nResult = ID; 
            }
            catch
            {
                nResult = 0; 
            }
            return nResult;
        }


        public int UpdateStatus(int ID, int Status)
        {
            int nResult = 0;
            cFAQs objDAL = new cFAQs();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Status = Status;

                objDAL.Save();
                nResult = objDAL.FAQID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }

        private void MappingData(cFAQs objInfor)
        {
            objInfor.Question3 = Data.Question3; 
            objInfor.Question1 = Data.Question1; 
            objInfor.Question2 = Data.Question2; 
            objInfor.Answer3 = Data.Answer3; 
            objInfor.Answer1 = Data.Answer1; 
            objInfor.Answer2 = Data.Answer2; 
            objInfor.Status = Data.Status;
            objInfor.Count = Data.Count;
            objInfor.FAQCategoryID = Data.FAQCategoryID;
            objInfor.ModifiedDate = Data.ModifiedDate;

        }

        private void ConvertData(cFAQs objInfor)
        {
            Data.Question3 =objInfor.Question3  ;
            Data.Question1 =objInfor.Question1 ;
            Data.Question2  =objInfor.Question2 ;
            Data.Answer3=objInfor.Answer3 ;
            Data.Answer1 =objInfor.Answer1  ;
            Data.Answer2 =objInfor.Answer2  ;
            Data.Status=objInfor.Status  ;
            Data.FAQCategoryID =objInfor.FAQCategoryID ;
            Data.ModifiedDate =objInfor.ModifiedDate;
            try{Data.Count = objInfor.Count;}
            catch{Data.Count = 0;}
        }

        public DataTable Search(int ItemView,int ItemID,  string Question, int FAQCatId, int DefaultLangId, int CurrentLangId, int Status,
                               int PageIndex, int PageSize, ref int PageCount)
        {
            DataTable tbResult = new DataTable();
            cFAQs objDAL = new cFAQs();
            tbResult = objDAL.Search(ItemView, ItemID ,Question, FAQCatId, DefaultLangId, CurrentLangId, Status, PageIndex, PageSize, ref  PageCount);
            return tbResult;
        }
        public int UpdateCount(int ID, int Count)
        {
            int nResult = 0;
            cFAQs objDAL = new cFAQs();
            try
            {
                objDAL.LoadByPrimaryKey(ID);
                objDAL.Count = Count;

                objDAL.Save();
                nResult = objDAL.FAQID;
            }
            catch
            {
                nResult = 0;
            }
            return nResult;
        }
        #endregion
    }
}
